#pragma once 

#include <iostream>
using namespace std;

class Task 
{
  public:
    // 构造函数要求创建任务对象时显示传入相关数据
    Task(int x = 0, int y = 0, char op = 0)
      :_x(x)
      ,_y(y)
      ,_op(op)
    {}

    // 解决任务的Run函数
    void Run()
    {
      int ret = 0;
      switch(_op)
      {
        case '+':
          ret = _x + _y;
          break;

        case '-':
          ret = _x - _y;
          break;

        case '*':
          ret = _x * _y;
          break;

        case '/':
          if(_y == 0)
          {
            cerr<<"div is error"<<endl;
            return;
          }
          else 
          {
            ret = _x / _y;
            break;
          }

        case '%':
          if(_y == 0)
          {
            cerr<<"div is error"<<endl;
            return;
          }
          else
          {
            ret = _x % _y;
            break;
          }

        default:
          cerr<<"operation error"<<endl;
          break;
      }
      cout<<"Thread["<<pthread_self()<<"]："<<_x<<' '<<_op<<' '<<_y<<' '<<'='<<' '<<ret<<endl;
    }

  private:
    // 运算数以及运算符
    int _x;
    int _y;
    char _op;
};
